package ca.starfarer.kobold.ui;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

/**
 * @author Kevin
 */
public class MainFrame extends JFrame implements ActionListener {

    private static final String APPLICATION_NAME = "Project Kobold";

    private JMenuItem mnuExit;

    public MainFrame() {
        super(APPLICATION_NAME);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setJMenuBar(createMenuBar());
        setSize(800, 600);
    }

    private JMenuBar createMenuBar() {
        JMenuBar menuBar = new JMenuBar();
        menuBar.add(createFileMenu());
        menuBar.add(createHelpMenu());
        return menuBar;
    }

    private JMenu createFileMenu() {
        JMenu fileMenu = new JMenu("File");
        fileMenu.setMnemonic(KeyEvent.VK_F);

        fileMenu.add(new JMenuItem("New Campaign...", KeyEvent.VK_C));
        fileMenu.add(new JMenuItem("New Library...", KeyEvent.VK_L));
        fileMenu.addSeparator();
        fileMenu.add(new JMenuItem("Import...", KeyEvent.VK_I));
        fileMenu.add(new JMenuItem("Export...", KeyEvent.VK_E));
        fileMenu.addSeparator();

        mnuExit = new JMenuItem("Exit", KeyEvent.VK_X);
        mnuExit.addActionListener(this);
        fileMenu.add(mnuExit);

        return fileMenu;
    }

    private JMenu createHelpMenu() {
        JMenu helpMenu = new JMenu("Help");
        helpMenu.setMnemonic(KeyEvent.VK_H);

        helpMenu.add(new JMenuItem("Dungeons & Dragons Compendium...", KeyEvent.VK_C));
        helpMenu.addSeparator();
        helpMenu.add(new JMenuItem("About...", KeyEvent.VK_A));

        return helpMenu;
    }

    public void actionPerformed(ActionEvent event) {
        Object source = event.getSource();
        if (source == mnuExit) {
            onExit();
        }
    }

    private void onExit() {
        dispose();
    }

}
